package com.xiongwei.factory;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

/**
 * 披萨项目新需求：客户点披萨时，可以点不同口味的，比如北京的奶酪披萨，北京的胡椒披萨
 * @author XiongWei
 * @date 2024/1/9
 */
public abstract class FactoryMethod {

    abstract Pizza createPizza(String type);

    public FactoryMethod() {
        do {
            Pizza pizza = createPizza(getType());
            if (pizza!= null) {
                pizza.prepare();
                pizza.bake();
                pizza.cut();
                pizza.box();
            } else {
                System.out.println("没有该种披萨");
            }
        } while (true);
    }

    /**
     * 客户键入pizza种类
     * @return
     */
    public String getType() {
        BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(System.in));
        System.out.println("请输入pizza种类");
        String s = null;
        try {
            s = bufferedReader.readLine();
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
        return s;
    }

    public static void main(String[] args) {
        FactoryMethod pizza = new OrderPizza3();
        pizza.createPizza(pizza.getType());
    }
}
